package com.zlx.sharelive.activity;

import android.content.Intent;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.zlx.module_base.base_ac.BaseAc;
import com.zlx.module_base.base_api.res_data.AgreementBean;
import com.zlx.module_base.base_api.util.ApiUtil;
import com.zlx.module_network.api1.livedata.BaseObserver;
import com.zlx.module_network.api1.livedata.BaseObserverCallBack;
import com.zlx.module_network.bean.ApiResponse;
import com.zlx.sharelive.R;
import com.zlx.sharelive.utils.Glide4Engine;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import me.bzcoder.mediapicker.SmartMediaPicker;
import me.bzcoder.mediapicker.config.MediaPickerEnum;

/**
 * 女神认证
 */
public class GoddessAc extends BaseAc {

    @BindView(R.id.tv_request)
    TextView tv_request;
    @BindView(R.id.tv_rights)
    TextView tv_rights;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_goddess;
    }


    @Override
    public void initViews() {
        super.initViews();

        getAgreement1("8");
        getAgreement2("9");
    }


    private void getAgreement1(String type) {
        ApiUtil.getHomeApi().getAgreement(type).observe(this, new BaseObserver<>(new BaseObserverCallBack<ApiResponse<AgreementBean>>() {
            @Override
            public void onSuccess(ApiResponse<AgreementBean> data) {
                if (null != data) {
                    if (null != data.getData()) {
                        if (null != data.getData().getInfo()) {
                            if (data.getData().getInfo().size() > 0) {
                                tv_request.setText(Html.fromHtml(data.getData().getInfo().get(0).getPost_content(), null, null));
                            }
                        }
                    }
                }
            }

            @Override
            public void onFinish() {
                super.onFinish();

            }
        }));
    }

    private void getAgreement2(String type) {
        ApiUtil.getHomeApi().getAgreement(type).observe(this, new BaseObserver<>(new BaseObserverCallBack<ApiResponse<AgreementBean>>() {
            @Override
            public void onSuccess(ApiResponse<AgreementBean> data) {
                if (null != data) {
                    if (null != data.getData()) {
                        if (null != data.getData().getInfo()) {
                            if (data.getData().getInfo().size() > 0) {
                                tv_rights.setText(Html.fromHtml(data.getData().getInfo().get(0).getPost_content(), null, null));
                            }
                        }
                    }
                }
            }

            @Override
            public void onFinish() {
                super.onFinish();

            }
        }));
    }

    @OnClick({R.id.iv_back, R.id.bt_authentication})
    public void setOnClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.bt_authentication:
                SmartMediaPicker.builder(this)
                        //最大图片选择数目 如果不需要图片 将数目设置为0
                        .withMaxImageSelectable(0)
                        //最大视频选择数目 如果不需要视频 将数目设置为0
                        .withMaxVideoSelectable(1)
                        //最大视频长度
                        .withMaxVideoLength(600 * 1000)
                        //最大视频文件大小 单位MB
                        .withMaxVideoSize(1024)
                        //设置图片加载引擎
                        .withImageEngine(new Glide4Engine())
                        //前置摄像头拍摄是否镜像翻转图像
                        .withIsMirror(false)
                        //弹出类别，默认弹出底部选择栏，也可以选择单独跳转
                        .withMediaPickerType(MediaPickerEnum.BOTH)
                        .build()
                        .show();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        List<String> resultData = SmartMediaPicker.getResultData(this, requestCode, resultCode, data);
        if (resultData != null && resultData.size() > 0) {
            startActivity(new Intent(GoddessAc.this, GoddessUpAc.class)
                    .putExtra("path", String.valueOf(resultData.toArray()[0])));
        } else {

        }
    }
}
